from django.db.models.signals import post_save
from django.dispatch import receiver
from .serializers import UserNotificationSerializer
from .models import UserNotification
from .services import send_real_time_notification


@receiver(post_save, sender=UserNotification)
def handle_new_notification(sender, instance, created, **kwargs):
    if created:
        send_real_time_notification(
            user_id=instance.user.id,
            notification_data=UserNotificationSerializer(instance).data,
        )
